<template>
  <div>
    <header style="display: flex; justify-content: space-between">
      <div style="display: flex">
        <h1>电路名：{{ circuitName }}</h1>
        <el-button
          style="margin-left: 20px; margin-top: -3px"
          @click="showDialog = true;console.log(fileUpload.value)"
        >修改
        </el-button
        >
      </div>
      <div>
        <el-button
          type="primary"
          style="
            margin-right: 20px;
            margin-top: -3px;
            height: 35px;
            font-size: 18px;
            background-color: #595959;
          "
          @click="back"
        >关闭该页面
        </el-button
        >
      </div>
    </header>
    <main style="display: flex; justify-content: center; align-items: center">
      <el-card style="width: 90%; display: flex; justify-content: center">
        <el-scrollbar
          max-height="650px"
          style="width: 100%; height: auto; display: flex"
        >
          <el-form
            :model="configForm"
            :rules="rules"
            label-width="300px"
            style="width: 100%; flex-direction: column; font-size: 30px"
            size="large"
          >
            <el-form-item>
              <el-button type="danger" size="default" @click="clearAllFiles">
                清空所有文件
              </el-button>
            </el-form-item>
            <!-- 其他表单标签显示配置信息 -->
            <el-form-item
              label="默认sp文件:"
              prop="property1"
              style="margin-bottom: 10px"
            >
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".sp"
                @change="handleFileChange('property1', $event)"
              >
                <el-input
                  v-model="configForm.property1"
                  class="inputStyles"
                  readonly
                ></el-input>
              </el-upload>
            </el-form-item>
            <el-form-item
              label="电路结构netlist文件:"
              prop="property2"
              style="margin-bottom: 10px"
            >
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".netlist"
                @change="handleFileChange('property2', $event)"
              >
                <el-input
                  v-model="configForm.property2"
                  class="inputStyles"
                  readonly
                ></el-input>
              </el-upload>
            </el-form-item>
            <el-form-item
              label="温度mod默认文件:"
              prop="property3"
              style="margin-bottom: 10px"
            >
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".mod"
                @change="handleFileChange('property3', $event)"
              >
                <el-input
                  v-model="configForm.property3"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item
              label="AI_fixed文件:"
              prop="property4"
              style="margin-bottom: 10px"
            >
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".txt"
                @change="handleFileChange('property4', $event)"
              >
                <el-input
                  v-model="configForm.property4"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item
              label="AI_change文件:"
              prop="property5"
              style="margin-bottom: 10px"
            >
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".txt"
                @change="handleFileChange('property5', $event)"
              >
                <el-input
                  v-model="configForm.property5"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item label="是否进行温度仿真:" style="margin-bottom: 10px">
                <el-checkbox v-model="caseSelected"></el-checkbox>
            </el-form-item>
            <el-form-item label="低温mod文件:" style="margin-bottom: 10px">
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".mod"
                @change="handleFileChange('property6', $event)"
              >
                <el-input
                  :disabled="isDisable1"
                  v-model="configForm.property6"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>

            <el-form-item label="高温mod文件:" style="margin-bottom: 10px">
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".mod"
                @change="handleFileChange('property7', $event)"
              >
                <el-input
                  :disabled="isDisable1"
                  v-model="configForm.property7"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item label="ra文件:" style="margin-bottom: 10px">
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".txt"
                @change="handleFileChange('property8', $event)"
              >
                <el-input
                  :disabled="isDisable1"
                  v-model="configForm.property8"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item
              label="蒙特卡洛默认sp文件:"
              style="margin-bottom: 10px"
            >
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".sp"
                @change="handleFileChange('property9', $event)"
              >
                <el-input
                  v-model="configForm.property9"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item
              label="蒙特卡洛netlist文件:"
              style="margin-bottom: 10px"
            >
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                @change="handleFileChange('property10', $event)"
              >
                <el-input
                  placeholder="本配置文件兼容AI_fixed文件"
                  v-model="configForm.property10"
                  readonly
                  style="width: 850px"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item
              label="蒙特卡洛温度mod默认文件:"
              style="margin-bottom: 10px"
            >
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                @change="handleFileChange('property11', $event)"
              >
                <el-input
                  placeholder="本配置文件兼容AI_change文件"
                  v-model="configForm.property11"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item label="蒙特卡洛ra文件:" style="margin-bottom: 10px">
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".txt"
                @change="handleFileChange('property12', $event)"
              >
                <el-input
                  :disabled="isDisable2"
                  v-model="configForm.property12"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
<!--            <el-form-item label="issue1_陡降_sp文件:" style="margin-bottom: 10px">
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".sp"
                @change="handleFileChange('property13', $event)"
              >
                <el-input
                  v-model="configForm.property13"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item
              label="issue1_陡降_netlist文件:"
              style="margin-bottom: 10px"
            >
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".netlist"
                @change="handleFileChange('property14', $event)"
              >
                <el-input
                  v-model="configForm.property14"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item label="issue1_陡降_mod文件:" style="margin-bottom: 10px">
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".mod"
                @change="handleFileChange('property15', $event)"
              >
                <el-input
                  v-model="configForm.property15"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item label="issue2_骤降_PWQ上限验证_sp文件:" style="margin-bottom: 10px">
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".sp"
                @change="handleFileChange('property16', $event)"
              >
                <el-input
                  v-model="configForm.property16"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item
              label="issue2_骤降_PWQ上限验证_netlist文件:"
              style="margin-bottom: 10px"
            >
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".netlist"
                @change="handleFileChange('property17', $event)"
              >
                <el-input
                  v-model="configForm.property17"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item>
            <el-form-item label="issue2_骤降_PWQ上限验证_mod文件:" style="margin-bottom: 10px">
              <el-upload
                action="#"
                :auto-upload="false"
                :show-file-list="false"
                accept=".mod"
                @change="handleFileChange('property18', $event)"
              >
                <el-input
                  v-model="configForm.property18"
                  readonly
                  class="inputStyles"
                ></el-input
                >
              </el-upload>
            </el-form-item> -->
          </el-form>
        </el-scrollbar>
        <div
          style="display: flex; align-items: center; justify-content: center"
        >
          <el-button
            type="primary"
            @click="uploadConfig"
            style="font-size: 20px; height: 35px; background-color: #003f82"
          >上传配置
          </el-button
          >
        </div>
      </el-card>
    </main>
    <!-- 弹窗 -->
    <el-dialog title="修改电路名" v-model="showDialog" width="30%">
      <el-form :model="form" label-width="120px">
        <el-form-item label="原电路名">
          <el-input v-model="form.old_circuit_diagram_name" disabled></el-input>
        </el-form-item>
        <el-form-item label="新电路名">
          <el-input v-model="form.new_circuit_diagram_name"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="showDialog = false">取消</el-button>
          <el-button type="primary" @click="submitForm">提交</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="电路配置">
import { ref, onMounted,watch } from "vue";
import { useRoute } from "vue-router";
import { ElMessage } from "element-plus";
import {
  reCircuitName,
  huada_config_upload,
  getUploadFiles,
  huada_config_upload_pre
} from "@/server/circuit";
import router from "@/router/index.js";


const caseSelected = ref(false);
const route = useRoute();
const circuitName = ref("...");
const configFile = ref({
  fileNameSp: "",
  fileNameMengSp: ""
});

const back = () => {
  router.back();
};

const getUploadFile = async () => {
  try {
    const response = await getUploadFiles({
      circuit_diagram_name: route.params.circuitName
    });
    console.log(response);
    const fileMap = {
      AI_change文件_n: "AI_change文件",
      AI_fixed文件_n: "AI_fixed文件",
      温度mod默认文件_n: "温度mod默认文件",
      电路结构netlist文件_n: "电路结构netlist文件",
      蒙特卡洛温度mod默认文件_n: "蒙特卡洛温度mod默认文件",
      蒙特卡洛netlist文件_n: "蒙特卡洛netlist文件",
      蒙特卡洛sp文件_n: "蒙特卡洛sp文件",
      默认sp文件_n: "默认sp文件",
      温度mod文件1_n: "温度mod文件1",
      温度mod文件2_n: "温度mod文件2",
      ra文件_n: "ra文件",
      蒙特卡洛ra文件_n: "蒙特卡洛ra文件",
      蒙特卡洛AI_change文件_n: "蒙特卡洛AI_change文件",
      蒙特卡洛AI_fixed文件_n: "蒙特卡洛AI_fixed文件",
      issue1_sp文件_n: "issue1_sp文件",
      issue1_netlist文件_n: "issue1_netlist文件",
      issue1_mod文件_n: "issue1_mod文件",
      issue2_sp文件_n: "issue2_sp文件",
      issue2_netlist文件_n: "issue2_netlist文件",
      issue2_mod文件_n: "issue2_mod文件"
    };
    for (const [key, value] of Object.entries(response)) {
      if (key.endsWith("_n")) {
        const fileName = key;
        const _nFileName = value;
        const fileContentKey = key.replace(/_n$/, "_c");
        if (response.hasOwnProperty(fileContentKey)) {
          const fileContent = response[fileContentKey];
          const blob = new Blob([fileContent], {
            type: "text/plain"
          });
          const file = new File([blob], _nFileName, {
            type: "text/plain"
          });
          if (fileMap[fileName]) {
            fileUpload.value[fileMap[fileName]] = file;
            switch (fileName) {
              case "AI_change文件_n":
                configForm.value.property5 =
                  fileUpload.value.AI_change文件.name;
                break;
              case "AI_fixed文件_n":
                configForm.value.property4 = fileUpload.value.AI_fixed文件.name;
                break;
              case "温度mod默认文件_n":
                configForm.value.property3 =
                  fileUpload.value.温度mod默认文件.name;
                break;
              case "电路结构netlist文件_n":
                configForm.value.property2 =
                  fileUpload.value.电路结构netlist文件.name;
                break;
              case "蒙特卡洛AI_change文件_n":
                configForm.value.property11 =
                  fileUpload.value.蒙特卡洛AI_change文件.name
                break;
              case "蒙特卡洛温度mod默认文件_n":
                configForm.value.property11 =
                  fileUpload.value.蒙特卡洛温度mod默认文件.name ;
                break;
              case "蒙特卡洛netlist文件_n":
                configForm.value.property10 =
                  fileUpload.value.蒙特卡洛netlist文件.name
                break;
              case "蒙特卡洛AI_fixed文件_n":
                configForm.value.property10 =
                  fileUpload.value.蒙特卡洛AI_fixed文件.name;
                break;
              case "蒙特卡洛sp文件_n":
                configForm.value.property9 =
                  fileUpload.value.蒙特卡洛sp文件.name;
                break;
              case "默认sp文件_n":
                configForm.value.property1 = fileUpload.value.默认sp文件.name;
                break;
              case "温度mod文件1_n":
                configForm.value.property6 = fileUpload.value.温度mod文件1.name;
                break;
              case "温度mod文件2_n":
                configForm.value.property7 = fileUpload.value.温度mod文件2.name;
                break;
              case "ra文件_n":
                configForm.value.property8 = fileUpload.value.ra文件.name;
                break;
              case "蒙特卡洛ra文件_n":
                configForm.value.property12 =
                  fileUpload.value.蒙特卡洛ra文件.name;
                break;
              case "issue1_sp文件_n":
                configForm.value.property13 =
                  fileUpload.value.issue1_sp文件.name;
                break;
              case "issue1_netlist文件_n":
                configForm.value.property14 =
                  fileUpload.value.issue1_netlist文件.name;
                break;
              case "issue1_mod文件_n":
                configForm.value.property15 =
                  fileUpload.value.issue1_mod文件.name;
                break;
              case "issue2_sp文件_n":
                configForm.value.property16 =
                  fileUpload.value.issue2_sp文件.name;
                break;
              case "issue2_netlist文件_n":
                configForm.value.property17 =
                  fileUpload.value.issue2_netlist文件.name;
                break;
              case "issue2_mod文件_n":
                configForm.value.property18 =
                  fileUpload.value.issue2_mod文件.name;
                break;
              default:
                console.log(`Unknown file: ${fileName}`);
            }
          } else {
            console.log(`Unknown file: ${fileName}`);
          }
        } else {
          console.error(`Content for file ${fileName} not found`);
        }
      }
    }
    console.log("console.log(fileUpload.value):", fileUpload.value);
  } catch (e) {
    console.error("e:", e);
    ElMessage.info("请上传文件");
  }
};
const configForm = ref({
  circuit: route.params.circuitName,
  property1: "",
  property2: "",
  property3: "",
  property4: "",
  property5: "",
  property6: "",
  property7: "",
  property8: "",
  property9: "",
  property10: "",
  property11: "",
  property12: "",
  property13: "",
  property14: "",
  property15: "",
  property16: "",
  property17: "",
  property18: ""
});
const configFormzh_CN = ref({
  电路名称: route.params.circuitName,
  默认sp文件: "",
  电路结构netlist文件: "",
  温度mod默认文件: "",
  AI_fixed文件: "",
  AI_change文件: "",
  温度mod文件1: "",
  温度mod文件2: "",
  ra文件: "",
  蒙特卡洛sp文件: "",
  蒙特卡洛netlist文件: "",
  蒙特卡洛温度mod默认文件: "",
  蒙特卡洛ra文件: "",
  issue1_sp文件: "",
  issue1_netlist文件: "",
  issue1_mod文件: "",
  issue2_sp文件: "",
  issue2_netlist文件: "",
  issue2_mod文件: ""
});
const rules = {
  fileNameSp: [
    {
      required: true,
      message: "请上传基础仿真sp文件",
      trigger: "change"
    }
  ],
  property1: [
    {
      required: true,
      message: "请上传默认sp文件",
      trigger: "change"
    }
  ],
  property2: [
    {
      required: true,
      message: "请上传电路结构netlist文件",
      trigger: "change"
    }
  ],
  property3: [
    {
      required: true,
      message: "请上传温度mod默认文件",
      trigger: "change"
    }
  ],
  property4: [
    {
      required: true,
      message: "请上传AI_fixed文件",
      trigger: "change"
    }
  ],
  property5: [
    {
      required: true,
      message: "请上传AI_change文件",
      trigger: "change"
    }
  ]
};
const fileUpload = ref({});

// 处理文件选择变化
function handleFileChange(property, event) {
  const file = event;
  console.log(file);
  fileUpload.value[property] = file;
  console.log(fileUpload.value);
  if (file && file.raw) {
    configForm.value[property] = file.name;
    configFile.value[property] = file.name;
  } else {
    console.log("No file found or file structure is unexpected.");
  }
}

// 上传配置
async function uploadConfig() {
  let response;
  if (
    configForm.value.property1 == "" ||
    configForm.value.property2 == "" ||
    configForm.value.property3 == "" ||
    configForm.value.property4 == "" ||
    configForm.value.property5 == ""
  ) {
    confirm("请先上传必须文件");
    ElMessage.error("操作失败");
  } else {
    try {
      response = await getUploadFiles({
        circuit_diagram_name: route.params.circuitName
      });
      try {
        // const isConfim = confirm("检测到当前电路之前上传过文件，请问是否继续上传，若是该电路存在演算结果，将会根据修改的文件，修改对应条目计算结果。")
        // if(!isConfim){
        //   return;
        // }
        const formData = new FormData();
        if (fileUpload.value != null) {
          formData.append("电路名称", configFormzh_CN.value.电路名称);
          formData.append(
            "默认sp文件",
            fileUpload.value.property1
              ? fileUpload.value.property1.raw
              : fileUpload.value.默认sp文件
          );
          formData.append(
            "电路结构netlist文件",
            fileUpload.value.property2
              ? fileUpload.value.property2.raw
              : fileUpload.value.电路结构netlist文件
          );
          formData.append(
            "温度mod默认文件",
            fileUpload.value.property3
              ? fileUpload.value.property3.raw
              : fileUpload.value.温度mod默认文件
          );
          formData.append(
            "AI_fixed文件",
            fileUpload.value.property4
              ? fileUpload.value.property4.raw
              : fileUpload.value.AI_fixed文件
          );
          formData.append(
            "AI_change文件",
            fileUpload.value.property5
              ? fileUpload.value.property5.raw
              : fileUpload.value.AI_change文件
          );
          formData.append(
            "温度mod文件1",
            fileUpload.value.property6
              ? fileUpload.value.property6.raw
              : fileUpload.value.温度mod文件1
          );
          formData.append(
            "温度mod文件2",
            fileUpload.value.property7
              ? fileUpload.value.property7.raw
              : fileUpload.value.温度mod文件2
          );
          formData.append(
            "ra文件",
            fileUpload.value.property8
              ? fileUpload.value.property8.raw
              : fileUpload.value.ra文件
          );
          formData.append(
            "蒙特卡洛sp文件",
            fileUpload.value.property9
              ? fileUpload.value.property9.raw
              : fileUpload.value.蒙特卡洛sp文件
          );
          formData.append(
            "蒙特卡洛netlist文件",
            fileUpload.value.property10
              ? fileUpload.value.property10.raw
              : (fileUpload.value.蒙特卡洛netlist文件 || fileUpload.value.蒙特卡洛AI_fixed文件)
          );
          formData.append(
            "蒙特卡洛温度mod默认文件",
            fileUpload.value.property11
              ? fileUpload.value.property11.raw
              : (fileUpload.value.蒙特卡洛AI_change文件 || fileUpload.value.蒙特卡洛温度mod默认文件)
          );
          formData.append(
            "蒙特卡洛ra文件",
            fileUpload.value.property12
              ? fileUpload.value.property12.raw
              : fileUpload.value.蒙特卡洛ra文件
          );
          formData.append(
            "issue1_sp文件",
            fileUpload.value.property13
              ? fileUpload.value.property13.raw
              : fileUpload.value.issue1_sp文件
          );
          formData.append(
            "issue1_netlist文件",
            fileUpload.value.property14
              ? fileUpload.value.property14.raw
              : fileUpload.value.issue1_netlist文件
          );
          formData.append(
            "issue1_mod文件",
            fileUpload.value.property15
              ? fileUpload.value.property15.raw
              : fileUpload.value.issue1_mod文件
          );
          formData.append(
            "issue2_sp文件",
            fileUpload.value.property16
              ? fileUpload.value.property16.raw
              : fileUpload.value.issue2_sp文件
          );
          formData.append(
            "issue2_netlist文件",
            fileUpload.value.property17
              ? fileUpload.value.property17.raw
              : fileUpload.value.issue2_netlist文件
          );
          formData.append(
            "issue2_mod文件",
            fileUpload.value.property18
              ? fileUpload.value.property18.raw
              : fileUpload.value.issue2_mod文件
          );
          formData.append(
            "温度仿真",caseSelected.value
          );
        }

        console.log("fileUpload.value:", fileUpload.value);
        response = await huada_config_upload_pre(formData);
        console.log(response)
        if(response.content&&(response.content!=null||response.content!='')){
          const isConfirm =  confirm(`${response.content},请确认是否继续`) 
          if(isConfirm){
              try{
                 await huada_config_upload(formData); 
                 ElMessage.success("上传成功");
              }catch(e){
                  ElMessage.error("上传失败");
              }
          }else{
              return;
          }
        }else{
            try{
               await huada_config_upload(formData); 
               ElMessage.success("上传成功");
            }catch(e){
                ElMessage.error("上传失败");
            }
        }
      } catch (e) {
        console.error(e);
        confirm("上传失败，请检查电路信息，是否缺少文件或者已拥有演算结果");
        ElMessage.error("上传失败");
      }
    }catch (e){
      try {
        const formData = new FormData();
        if (fileUpload.value != null) {
            formData.append(
              "温度仿真",caseSelected.value
            );
          formData.append("电路名称", configFormzh_CN.value.电路名称);
          formData.append(
            "默认sp文件",
            fileUpload.value.property1
              ? fileUpload.value.property1.raw
              : fileUpload.value.默认sp文件
          );
          formData.append(
            "电路结构netlist文件",
            fileUpload.value.property2
              ? fileUpload.value.property2.raw
              : fileUpload.value.电路结构netlist文件
          );
          formData.append(
            "温度mod默认文件",
            fileUpload.value.property3
              ? fileUpload.value.property3.raw
              : fileUpload.value.温度mod默认文件
          );
          formData.append(
            "AI_fixed文件",
            fileUpload.value.property4
              ? fileUpload.value.property4.raw
              : fileUpload.value.AI_fixed文件
          );
          formData.append(
            "AI_change文件",
            fileUpload.value.property5
              ? fileUpload.value.property5.raw
              : fileUpload.value.AI_change文件
          );
          formData.append(
            "温度mod文件1",
            fileUpload.value.property6
              ? fileUpload.value.property6.raw
              : fileUpload.value.温度mod文件1
          );
          formData.append(
            "温度mod文件2",
            fileUpload.value.property7
              ? fileUpload.value.property7.raw
              : fileUpload.value.温度mod文件2
          );
          formData.append(
            "ra文件",
            fileUpload.value.property8
              ? fileUpload.value.property8.raw
              : fileUpload.value.ra文件
          );
          formData.append(
            "蒙特卡洛sp文件",
            fileUpload.value.property9
              ? fileUpload.value.property9.raw
              : fileUpload.value.蒙特卡洛sp文件
          );
          formData.append(
            "蒙特卡洛netlist文件",
            fileUpload.value.property10
              ? fileUpload.value.property10.raw
              : (fileUpload.value.蒙特卡洛netlist文件 || fileUpload.value.蒙特卡洛AI_fixed文件)
          );
          formData.append(
            "蒙特卡洛温度mod默认文件",
            fileUpload.value.property11
              ? fileUpload.value.property11.raw
              : (fileUpload.value.蒙特卡洛AI_change文件 || fileUpload.value.蒙特卡洛温度mod默认文件)
          );
          formData.append(
            "蒙特卡洛ra文件",
            fileUpload.value.property12
              ? fileUpload.value.property12.raw
              : fileUpload.value.蒙特卡洛ra文件
          );
          formData.append(
            "issue1_sp文件",
            fileUpload.value.property13
              ? fileUpload.value.property13.raw
              : fileUpload.value.issue1_sp文件
          );
          formData.append(
            "issue1_netlist文件",
            fileUpload.value.property14
              ? fileUpload.value.property14.raw
              : fileUpload.value.issue1_netlist文件
          );
          formData.append(
            "issue1_mod文件",
            fileUpload.value.property15
              ? fileUpload.value.property15.raw
              : fileUpload.value.issue1_mod文件
          );
          formData.append(
            "issue2_sp文件",
            fileUpload.value.property16
              ? fileUpload.value.property16.raw
              : fileUpload.value.issue2_sp文件
          );
          formData.append(
            "issue2_netlist文件",
            fileUpload.value.property17
              ? fileUpload.value.property17.raw
              : fileUpload.value.issue2_netlist文件
          );
          formData.append(
            "issue2_mod文件",
            fileUpload.value.property18
              ? fileUpload.value.property18.raw
              : fileUpload.value.issue2_mod文件
          );
        }

        console.log("fileUpload.value:", fileUpload.value);
        response = await huada_config_upload(formData);
        ElMessage.success("上传成功");
      } catch (e) {
        console.log(response);
        confirm("上传失败，请检查电路信息，是否缺少文件或者已拥有演算结果");
        ElMessage.error("上传失败");
      }
    }

  }
}

const showDialog = ref(false); // 控制弹窗显示隐藏
const form = ref({
  old_circuit_diagram_name: "",
  new_circuit_diagram_name: ""
});
const submitForm = async () => {
  if (form.value.new_circuit_diagram_name.trim() === "") {
    ElMessage.error("新电路名不能为空");
    return;
  }
  try {
    await reCircuitName(form.value);
    circuitName.value = form.value.new_circuit_diagram_name;
    showDialog.value = false; // 关闭弹窗
    ElMessage.success("电路名修改成功");
    router.push({
      name: "电路配置",
      params: {
        circuitName: circuitName.value
      }
    });
  } catch (e) {
    showDialog.value = false;
    confirm("修改失败，电路可能存在仿真结果或电路名重复");
  }
};

const clearAllFiles = () =>{
  const isConfirm =  confirm("本清空文件功能，只能清除非标注必选的文件，且为了防止误操作，需要手动点击上传配置按钮，是否继续？")
  if(isConfirm){
    if(fileUpload.value.property6){
      fileUpload.value.property6=null;
      configForm.value.property6='';
    }
    if(fileUpload.value.温度mod文件1){
      fileUpload.value.温度mod文件1=null;
      configForm.value.property6='';
    }
    if (fileUpload.value.property7){
      fileUpload.value.property7=null;
      configForm.value.property7='';
    }
    if (fileUpload.value.温度mod文件2){
      fileUpload.value.温度mod文件2=null;
      configForm.value.property7='';
    }
    if(fileUpload.value.property8){
      fileUpload.value.property8=null;
      configForm.value.property8='';
    }
    if (fileUpload.value.ra文件){
      fileUpload.value.ra文件=null;
      configForm.value.property8='';
    }
    if(fileUpload.value.property9){
      fileUpload.value.property9=null;
      configForm.value.property9='';
    }
    if(fileUpload.value.蒙特卡洛sp文件){
      fileUpload.value.蒙特卡洛sp文件=null;
      configForm.value.property9='';
    }
    if(fileUpload.value.蒙特卡洛netlist文件){
      fileUpload.value.蒙特卡洛netlist文件=null;
      configForm.value.property10='';
    }
    if(fileUpload.value.蒙特卡洛AI_fixed文件){
      fileUpload.value.蒙特卡洛AI_fixed文件=null;
      configForm.value.property10='';
    }
    if(fileUpload.value.property11){
      fileUpload.value.property11=null;
      configForm.value.property11='';
    }
    if(fileUpload.value.蒙特卡洛温度mod默认文件){
      fileUpload.value.蒙特卡洛温度mod默认文件=null;
      configForm.value.property11='';
    }
    if(fileUpload.value.蒙特卡洛AI_change文件){
      fileUpload.value.蒙特卡洛AI_change文件=null;
      configForm.value.property11='';
    }
    if(fileUpload.value.property12){
      fileUpload.value.property12=null;
      configForm.value.property12='';
    }
    if(fileUpload.value.蒙特卡洛ra文件){
      fileUpload.value.蒙特卡洛ra文件=null;
      configForm.value.property12='';
    }
    if(fileUpload.value.property13){
      fileUpload.value.property13=null;
      configForm.value.property13='';
    }
    if(fileUpload.value.issue1_sp文件){
      fileUpload.value.issue1_sp文件=null;
      configForm.value.property13='';
    }
    if(fileUpload.value.property14){
      fileUpload.value.property14=null;
      configForm.value.property14='';
    }
    if(fileUpload.value.issue1_netlist文件){
      fileUpload.value.issue1_netlist文件=null;
      configForm.value.property14='';
    }
    if(fileUpload.value.property15){
      fileUpload.value.property15=null;
      configForm.value.property15='';
    }
    if(fileUpload.value.issue1_mod文件){
      fileUpload.value.issue1_mod文件=null;
      configForm.value.property15='';
    }
    if(fileUpload.value.property16){
      fileUpload.value.property16=null;
      configForm.value.property16='';
    }
    if(fileUpload.value.issue2_sp文件){
      fileUpload.value.issue2_sp文件=null;
      configForm.value.property16='';
    }
    if(fileUpload.value.property17){
      fileUpload.value.property17=null;
      configForm.value.property17='';
    }
    if(fileUpload.value.issue2_netlist文件){
      fileUpload.value.issue2_netlist文件=null;
      configForm.value.property17='';
    }
    if(fileUpload.value.property18){
      fileUpload.value.property18=null;
      configForm.value.property18='';
    }
    if(fileUpload.value.issue2_mod文件){
      fileUpload.value.issue2_mod文件=null;
      configForm.value.property18='';
    }
  }
};

const isDisable1= ref(false);
const isDisable2= ref(false);




onMounted(async() => {
   circuitName.value = route.params.circuitName;
   form.value.old_circuit_diagram_name = circuitName.value;
   getUploadFile();
});
</script>

<style scoped>
.inputStyles {
  width: 850px;
}

header {
  padding: 20px;
  background-color: #f8f9fa;
}

main {
  margin-top: 20px;
}

footer {
  text-align: center;
  margin-top: 20px;
}

.el-tag {
  margin: -5px 0 -15px 0;
}

</style>
